package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.Thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IMemberReservationService;
import io.swagger.annotations.Api;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: zzyl
 * @Version: 1.0
 * @Create: 2023-09-05 17:09
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "老人预约管理")
public class MemberReservationController {
    @Autowired
    private IMemberReservationService memberReservationService;

    /**
     * 获取预约取消数量
     * @return
     */
    @GetMapping("/cancelled-count")
    public R<Integer> selectReservationCountByDay() {
        Long userId = UserThreadLocal.getUserId();
        Integer i = memberReservationService.selectReservationCountByDay(userId);
        return  R.ok(i);
    }
    /**
     * 查询每个时间段剩余预约数
     */
    @GetMapping("/countByTime")
    public AjaxResult selectReservationCountByTime(Long time) {
        List<Map<String, Object>> list = memberReservationService.selectReservationCountByTime(time);
        return AjaxResult.success(list);
    }
    /**
     * 新增预约
     */
    @PostMapping
    public AjaxResult insertReservation(@RequestBody ReservationDto dto) {
        int i = memberReservationService.insertReservation(dto);
        return i > 0 ? AjaxResult.success("操作成功") : AjaxResult.error("操作失败");
    }

    /**
     * 分页查询预约列表
     */
    @GetMapping
    public TableDataInfo<List<Reservation>> list(Integer pageNum, Integer pageSize, Integer  status){
       return null;
    }

}
